package leader.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;

import leader.service.DirectPatentService;
import leader.service.LeaderService;

import teacher.bean.Award;
import teacher.bean.Paper;
import teacher.bean.Patent;
import teacher.bean.Teacher;

public class AllDirectPatentAction {
	private List<Patent> patent;
	private int currentpage;
	private int endpage;
	private int count;
	private int pagesize;
	private int flag;

	public List<Patent> getPatent() {
		return patent;
	}

	public void setPatent(List<Patent> patent) {
		this.patent = patent;
	}
	

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getEndpage() {
		return endpage;
	}

	public void setEndpage(int endpage) {
		this.endpage = endpage;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public String execute() {
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectPatentService pat = new DirectPatentService();
		pagesize = 10;
		count = pat.getCountOfDirectPatent(lea);
    	List<Award> awards = new ArrayList<Award>();
    	if(currentpage == 0) {
    		currentpage = 1;
    	}
    	int add = 0;
    	if(count%pagesize != 0) {
    		add = 1;
    	}
    	endpage = count/pagesize + add;
    	if(currentpage > endpage && endpage > 0 ) {
    		currentpage = endpage;
    	}
    	ActionContext.getContext().put("flag",0);
    	flag = 0;
		patent = pat.selectSegregateAllDirectPatent(lea, (currentpage-1)*pagesize+1, pagesize);
		return "success";
	}
}
